<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复用而非重新渲染</title>
</head>

<body>
    <div id="app">
        <!-- 属性值用大括号/小括号，属性值中字符串用小括号/大括号 -->
        <!-- v-if=" xxx = 'yyy' " -->
        <template v-if='type === "name"'>
            <label for="">用户名: </label>
            <input placeholder="请输入用户名">
        </template>
        <template v-else>
            <label for="">邮箱: </label>
            <input placeholder="请输入邮箱">
        </template>
        <button @click="handleToggleClick">切换输入类型</button>
    </div>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script>
        let app = new Vue({
            el: '#app',
            data() {
                return {
                    type: 'name'
                }
            },
            methods: {
                handleToggleClick: function(){
                    this.type = this.type === 'name' ? 'mail' : 'name';
                }
            }
        })
    </script>
</body>

</html>